import ToastComponent from './toast'

var $vm
let instance


function Toast (options){
	options = options || {}
	if(typeof options === 'string'){
		options = {
			name:options
		}
	}

	instance = new ToastComponent({
		el:document.createElement('div')
	})
	document.body.appendChild(instance.vm.$el)

	instance.vm = instance.$mount()



}

const install = vue => {
	const Toast = vue.extend(ToastComponent)

    if (!$vm) {
		$vm = new Toast({
			el: document.createElement('div')
		})
		document.body.appendChild($vm.$el)
	}

	var toast = {
		show ( options ){
			if( typeof options === 'string'){
				$vm.text = options
			}else{
				if(!!options.text) $vm.text = options.text
				if(!!options.time) $vm.time = options.time
			}
			$vm.show = true
		}
	}

	if (!vue.$vux) {
		vue.$vux = {
		  toast
		}
	} else {
		vue.$vux.toast = toast
	}

	vue.mixin({
		created: function(){
			this.$vux = vue.$vux
		}
	})
}

export default install


// export default {
// 	install: function( vue ){
// 		const Toast = vue.extend(ToastComponent);

// 		if(!$vm){
// 			$vm = new Toast({
// 				el: document.createElement('div')
// 			})
// 			document.body.appendChild($vm.$el)
// 		}

// 	}
// }
